package com.raising.modules.sys.entity;

import com.raising.ConstantParam;
import com.raising.framework.entity.BaseEntity;
import org.springframework.util.CollectionUtils;
import org.springframework.util.StringUtils;

import java.util.ArrayList;
import java.util.List;

/**
 * 用户表
 * 
 * @author gaoy
 */
public class User extends BaseEntity<User> {

	private static final long serialVersionUID = 1L;

	/** 编号 */
	private String no;
	/** 用户名 */
	private String username;
	/** 密码 */
	private String password;
	/** 加密密码的盐 */
	private String salt;
	/** 拥有授权管理机构 */
	private List<String> manageOrgIds;
	/** 拥有授权管理机构 */
	private String manageOrgIdsStr;
	/** 拥有的角色列表 */
	private List<String> roleIds;
	/** 拥有的角色列表 */
	private String roleIdsStr;
	/** 是否锁定 */
	private Boolean locked = Boolean.FALSE;
	/** 是否部门管理员 */
	private Boolean isDept = Boolean.FALSE;
	/**岗位*/
	private  String stationNm;
	/** 是否离职 */
	private String isOff;
	/** 姓名或昵称 */
	private String name;
	/** 电子邮件 */
	private String email;
	/** 手机号 */
	private String phone;
	/** 头像 */
	private String photo;
	/** 登录授权码 */
	private String loginToken;
	/** 页面停留时间/秒 */
	private String stayTimes;
	/** 操作次数 */
	private String operatTimes;
	/** 登录次数 */
	private String loginTimes;
	/** 评价次数 */
	private String commentCount;
	/** 点击次数 */
	private String clickCount;
	/** 开始时间 */
	private String beginDt;
	/** 结束时间 */
	private String endDt;
	/** 用户类型 */
	private String userTypeCd;
	/** 用户类型 */
	private String userTypeNm;
	/** 性别 */
	private String sexCd;
	/** 是否展开 */
	private String isOpen;

	/** 单位标识 */
	private String orgId;
	private String orgNm;
	private String orgNo;

	public String getStationNm() {
		return stationNm;
	}

	public void setStationNm(String stationNm) {
		this.stationNm = stationNm;
	}

	public User() {
		super();
	}

	public User(String id) {
		super(id);
	}

	public User(String username, String password) {
		super();
		this.username = username;
		this.password = password;
	}
	
	public List<String> getManageOrgIds() {
		if (manageOrgIds == null) {
			manageOrgIds = new ArrayList<String>();
		}
		return manageOrgIds;
	}

	
	public void setManageOrgIds(List<String> manageOrgIds) {
		this.manageOrgIds = manageOrgIds;
	}

	public String getManageOrgIdsStr() {
		if (CollectionUtils.isEmpty(manageOrgIds)) {
			return "";
		}
		StringBuilder s = new StringBuilder();
		for (String manageOrgId : manageOrgIds) {
			s.append(manageOrgId);
			s.append(",");
		}
		String result = s.toString();
		if(result!=null&&result.endsWith(ConstantParam.COMMA)){
			result = result.substring(0,result.length()-1);
		}
		return result;
	}

	public void setManageOrgIdsStr(String manageOrgIdsStr) {
		if (StringUtils.isEmpty(manageOrgIdsStr)) {
			return;
		}
		String[] manageOrgIdsStrs = manageOrgIdsStr.split(ConstantParam.COMMA);
		for (String manageOrgIdStr : manageOrgIdsStrs) {
			if (StringUtils.isEmpty(manageOrgIdStr)) {
				continue;
			}
			getManageOrgIds().add(manageOrgIdStr);
		}
	}

	public String getUsername() {
		return username;
	}

	public void setUsername(String username) {
		this.username = username;
	}

	public String getPassword() {
		return password;
	}

	public void setPassword(String password) {
		this.password = password;
	}

	public String getSalt() {
		return salt;
	}

	public void setSalt(String salt) {
		this.salt = salt;
	}

	public List<String> getRoleIds() {
		if (roleIds == null) {
			roleIds = new ArrayList<String>();
		}
		return roleIds;
	}

	public void setRoleIds(List<String> roleIds) {
		this.roleIds = roleIds;
	}

	public String getRoleIdsStr() {
		if (CollectionUtils.isEmpty(roleIds)) {
			return "";
		}
		StringBuilder s = new StringBuilder();
		for (String roleId : roleIds) {
			s.append(roleId);
			s.append(",");
		}
		return s.toString();
	}

	public void setRoleIdsStr(String roleIdsStr) {
		if (StringUtils.isEmpty(roleIdsStr)) {
			return;
		}
		String[] roleIdStrs = roleIdsStr.split(",");
		for (String roleIdStr : roleIdStrs) {
			if (StringUtils.isEmpty(roleIdStr)) {
				continue;
			}
			getRoleIds().add(roleIdStr);
		}
	}

	public Boolean getLocked() {
		return locked;
	}

	public void setLocked(Boolean locked) {
		this.locked = locked;
	}

	public Boolean getIsDept() {
		return isDept;
	}

	public void setIsDept(Boolean isDept) {
		this.isDept = isDept;
	}
	
	public String getIsOff() {
		return isOff;
	}

	public void setIsOff(String isOff) {
		this.isOff = isOff;
	}

	public String getName() {
		return name;
	}

	public void setName(String name) {
		this.name = name;
	}

	public String getNo() {
		return no;
	}

	public void setNo(String no) {
		this.no = no;
	}

	public String getEmail() {
		return email;
	}

	public void setEmail(String email) {
		this.email = email;
	}

	public String getPhone() {
		return phone;
	}

	public void setPhone(String phone) {
		this.phone = phone;
	}

	public String getPhoto() {
		return photo;
	}

	public void setPhoto(String photo) {
		this.photo = photo;
	}
	
	public boolean isAdmin(){
		return isAdmin(this.id);
	}

	public static boolean isAdmin(String id){
		return id != null && "1".equals(id);
	}

	public String getLoginToken() {
		return loginToken;
	}

	public void setLoginToken(String loginToken) {
		this.loginToken = loginToken;
	}

	public String getStayTimes() {
		return stayTimes;
	}

	public void setStayTimes(String stayTimes) {
		this.stayTimes = stayTimes;
	}

	public String getOperatTimes() {
		return operatTimes;
	}

	public void setOperatTimes(String operatTimes) {
		this.operatTimes = operatTimes;
	}

	public String getLoginTimes() {
		return loginTimes;
	}

	public void setLoginTimes(String loginTimes) {
		this.loginTimes = loginTimes;
	}

	public String getCommentCount() {
		return commentCount;
	}

	public void setCommentCount(String commentCount) {
		this.commentCount = commentCount;
	}

	public String getClickCount() {
		return clickCount;
	}

	public void setClickCount(String clickCount) {
		this.clickCount = clickCount;
	}

	public String getBeginDt() {
		return beginDt;
	}

	public void setBeginDt(String beginDt) {
		this.beginDt = beginDt;
	}

	public String getEndDt() {
		return endDt;
	}

	public void setEndDt(String endDt) {
		this.endDt = endDt;
	}

	public String getUserTypeCd() {
		return userTypeCd;
	}

	public void setUserTypeCd(String userTypeCd) {
		this.userTypeCd = userTypeCd;
	}

	public String getUserTypeNm() {
		return userTypeNm;
	}

	public void setUserTypeNm(String userTypeNm) {
		this.userTypeNm = userTypeNm;
	}

	public String getSexCd() {
		return sexCd;
	}

	public void setSexCd(String sexCd) {
		this.sexCd = sexCd;
	}

	public String getIsOpen() {
		return isOpen;
	}

	public void setIsOpen(String isOpen) {
		this.isOpen = isOpen;
	}

	@Override
	public String getOrgId() {
		return orgId;
	}

	@Override
	public void setOrgId(String orgId) {
		this.orgId = orgId;
	}

	@Override
	public String getOrgNm() {
		return orgNm;
	}

	@Override
	public void setOrgNm(String orgNm) {
		this.orgNm = orgNm;
	}

	public String getOrgNo() {
		return orgNo;
	}

	public void setOrgNo(String orgNo) {
		this.orgNo = orgNo;
	}

	@Override
	public String toString() {
		return "User{" +
				"stationNm='" + stationNm + '\'' +
				", no='" + no + '\'' +
				", manageOrgIds=" + manageOrgIds +
				", manageOrgIdsStr='" + manageOrgIdsStr + '\'' +
				", username='" + username + '\'' +
				", password='" + password + '\'' +
				", salt='" + salt + '\'' +
				", roleIds=" + roleIds +
				", roleIdsStr='" + roleIdsStr + '\'' +
				", locked=" + locked +
				", isDept=" + isDept +
				", isOff='" + isOff + '\'' +
				", name='" + name + '\'' +
				", email='" + email + '\'' +
				", phone='" + phone + '\'' +
				", photo='" + photo + '\'' +
				", loginToken='" + loginToken + '\'' +
				", stayTimes='" + stayTimes + '\'' +
				", operatTimes='" + operatTimes + '\'' +
				", loginTimes='" + loginTimes + '\'' +
				", commentCount='" + commentCount + '\'' +
				", clickCount='" + clickCount + '\'' +
				", beginDt='" + beginDt + '\'' +
				", endDt='" + endDt + '\'' +
				", userTypeCd='" + userTypeCd + '\'' +
				", userTypeNm='" + userTypeNm + '\'' +
				", sexCd='" + sexCd + '\'' +
				", id='" + id + '\'' +
				'}';
	}
}
